package com.example.leetcode.leetcode.concurrent;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zhuhaitao
 * @email zhuhaitao@imoran.net
 * @date 2020/12/14 11:03 上午
 */
@Slf4j
public class Test {
    public static void main(String[] args) {
        LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(2);
        ExecutorService pool = new ThreadPoolExecutor(2, 3,
                0L, TimeUnit.MILLISECONDS,
                queue);
        for (int i = 1; i <= 5; i++) {
            int finalI = i;
            pool.submit(() -> {
                try {
                    System.out.println(finalI +Thread.currentThread().getName());
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
        }
    }
}
